<template>
    <div>
        <h1>房号添加</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>房号</td>
                    <td>
                        <input type="text" v-model="data.Hnum">
                    </td>
                </tr>

                <tr>
                    <td>价格</td>
                    <td>
                        <input type="text" v-model="data.Price">
                    </td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" v-model="data.State" name="state" :value="true">开启
                        <input type="radio" v-model="data.State" name="state" :value="false">关闭
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="Add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import axios from 'axios';

const data=ref({
    "Id": 0,
  "Hnum": "",
  "Price": "",
  "State": true,
  "IsDel": true
})

const Add=()=>{
    axios.post("https://localhost:7133/api/House/AddHouse",data.value).then(res=>{
        if(res.data==5){
            alert("房号重复");
            return;
        }
        if(res.data==1){
            alert("添加成功");
            location.href='/list';
        }else
        {
            alert("添加失败");
            return;
        }
    })
}

</script>

<style scoped>

</style>